package com.java.socket;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UDPOne {

	public static void main(String[] args) throws IOException {
		DatagramSocket socket = new DatagramSocket();
		String str = "如果上天知我心诚，就让石头也发芽吧。";
		DatagramPacket packet = new DatagramPacket(str.getBytes(),str.length(), InetAddress.getByName("localhost"),3000);
		socket.send(packet);

		byte[] bytes = new byte[1000];
		DatagramPacket packet1 = new DatagramPacket(bytes,100);
		socket.receive(packet1);
		System.out.println(new String(bytes, 0, packet1.getLength()));
		socket.close();
	}
}
